#pragma once

#include "Workspace/IView.h"
#include "command/StateContex.h"
#include "Layout.h"

interface IApplication;	interface IInteraction;

class View : public IView
{
public:
	BEGIN_DEFINE_CLASS(CLSID_View)
		DEFINE_INTERFACE_ENTRY(IView)
	END_DEFINE_CLASS()

	View();
	virtual ~View();

	virtual void Create(uintptr context,const Size& size);
	virtual void LinkDocument(IDocument* document);
	virtual void Draw(uintptr context,const Size& size);
	virtual void Close();
	virtual bool Event(SystemEventArgs* e);
	virtual bool IsActive();
	virtual void SetActive(bool active=true);

	virtual void Refresh();
	virtual void Refresh(const Rect& boundbox);
	virtual void Scroll();
	virtual StateContext* GetStateContext();

	virtual real GetScale() const;
	virtual void Scale(real scale,bool increase=true);
	virtual void SetViewPoint(const Point& viewpoint);
	virtual const Point& GetViewPoint() const;

	virtual IDocument* GetDocument() const;
	virtual IEventHandlers* GetEventHandlers() const;
	virtual IInteraction* GetInteraction() const;
	virtual Graphics* GetGraphics() const;

	void Update(IView* activeView);

	event_implement(CanvasRefreshingEventHandler,CanvasRefreshing);
	event_implement(ScrollEventHandler,Scrolling);

protected:
	bool DoLayout();

private:
	Size GetDeviceSize();
	IApplication* GetApplication();

	IDocument*  m_document;

	sys::ObjectPtr m_eventHandlers;
	sys::ObjectPtr m_displayworkflow;
	sys::ObjectPtr m_interaction;

	bool m_hascreated;
	real m_scale;
	Point m_viewpoint;
	bool m_active;

	Size m_clientSize;

	StateContext m_stateContext;

	PageLayoutInfo m_layout;
};

AUTO_REGISTER_CLASSMAP_ENTRY(View)